<?php

namespace app\api\controller;

use app\api\model\Comment as CommentModel;

/**
 * 商品评价控制器
 * Class Comment
 * @package app\api\controller
 */
class Comment extends Controller
{
    /**
     * 商品评价列表
     * @param $goods_id
     * @param int $scoreType
     * @return array
     * @throws \think\exception\DbException
     */
    public function lists($goods_id, $scoreType = -1)
    {
        $model = new CommentModel;
        $list = $model->getGoodsCommentList($goods_id, $scoreType);
        $total = $model->getTotal($goods_id);
        return $this->renderSuccess(compact('list', 'total'));
    }

    //晒单广场用
    public function lists_show()
    {
        $model = new CommentModel();
        $list = $model->getAllCommentList();

        
        foreach ($list as &$item) {
            if(strlen($item['user']['nickName']) >3)
            {
                $item['user']['nickName'] = \substr_cut($item['user']['nickName']);
            }

            
        }

        $s = \app\api\model\bargain\Setting::getBasic();
        $setting =array();
        $setting['button_name'] = $s['button_name'] ?? '免 费 拿';
        $setting['interval'] = $s['interval'] ?? 6;
        $setting['tips']  = '温馨提示: 分享评价晒单，可以尊享下次优先审核发货！'; 
        return $this->renderSuccess(compact('list', 'setting'));
    }

}